package example.factorybean;

import example.AppConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class TestFactoryBean {
	public static void main(String[] args) {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
		//下面这句代码会出现java.lang.ClassCastException: example.factorybean.ReturnedBean cannot be cast to example
		// .factorybean.MyFactoryBean
		//MyFactoryBean myFactoryBean = (MyFactoryBean) context.getBean("&myFactoryBean");
		//myFactoryBean.test();

		//这句代码也可以正常执行，也就是说通过beanid为&myFactoryBean得到的是MyFactoryBean
		MyFactoryBean myFactoryBean = (MyFactoryBean) context.getBean("&myFactoryBean");
		myFactoryBean.test();

		//这一句代码可以正常执行
		ReturnedBean returnedBean = (ReturnedBean) context.getBean("myFactoryBean");
		returnedBean.sayHello();
	}
}
